function AccountAssistant(argFromPusher) {
}

AccountAssistant.prototype = {
	country : null,
	zone : null,
	user: null,
	setup: function() {
		Ares.setupSceneAssistant(this);
		this.layout();
		var addr = null;
		if( addr = getStorageObject("address" + user.uid)){
			this.$.firstBox.setValue(addr.first);
			this.$.lastBox.setValue(addr.last);
			this.$.companyBox.setValue(addr.company);
			this.$.streetBox.setValue(addr.street);
			this.$.cityBox.setValue(addr.city);
			if(addr.country){
				this.country = addr.country;
				this.$.countryLbl.setLabel(addr.country.country_name);
			}
			if(addr.zone){
				this.zone = addr.zone;
				this.$.zoneLbl.setLabel(addr.zone.zone_name);
			}
			this.$.postalBox.setValue(addr.postal);
			this.$.phoneBox.setValue(addr.phone);
		}
		drupalService('user.get', {uid: user.uid}, this, function(data) {
			this.user = data;
			this.$.usernameBox.setValue(data.name);
			this.$.emailBox.setValue(data.mail);
		}.bind(this));
	},
	activate: function(event) {
		if(!event) return;
		if(event.country){
			this.country = event.country;
			this.$.countryLbl.setLabel(event.country.country_name);
		}
		else if(event.zone){
			this.zone = event.zone;
			this.$.zoneLbl.setLabel(event.zone.zone_name);
		}
	},
	cleanup: function() {
		Ares.cleanupSceneAssistant(this);
	},
	button1Tap: function(inSender, event) {
		var account = { uid: this.user.uid };
		account.name = this.$.usernameBox.getValue();
		account.mail = this.$.emailBox.getValue();
		account.pass = {
			pass1: this.$.passwordBox1.getValue(),
			pass2: this.$.passwordBox2.getValue()
		};
		var this1 = this;
		drupalService('user.save', {account: account}, this, function(data) {
			myAlert(this1, "Your account is saved successfully.", function(){
				Mojo.Controller.stageController.popScene();
				return;
			}, null, null, null, true);
	});
	},
	radioButton1Change: function(inSender, event) {
		this.layout();
	},
	layout: function(){
		if(this.$.radioButton1.getValue() == 1){
			this.$.acctPanel.setShowing(true);
			this.$.addrPanel.setShowing(false);
		}else{
			this.$.acctPanel.setShowing(false);
			this.$.addrPanel.setShowing(true);
		}
	},
	label1Tap: function(inSender, event) {
		Mojo.Controller.stageController.pushScene("countriesList");
	},
	label2Tap: function(inSender, event) {
		if(this.country != null)
			Mojo.Controller.stageController.pushScene("zonesList", {country_id: this.country.country_id});
		else
			myAlert(this, "Please select country.");
	},
	button2Tap: function(inSender, event) {
		var addr = {
			first:		this.$.firstBox.getValue(),
			last:			this.$.lastBox.getValue(),
			company:	this.$.companyBox.getValue(),
			street:		this.$.streetBox.getValue(),
			city:			this.$.cityBox.getValue(),
			country:	this.country,
			zone:			this.zone,
			postal:		this.$.postalBox.getValue(),
			phone:		this.$.phoneBox.getValue()
		};
		setStorageObject("address" + user.uid, addr);
		myAlert(this, "Address is saved.", null, null, null, null, true);
	}
};